-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tabular UI for naming linked files #12624
base: main
Are you sure you want to change the base?
Conversation
src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.java
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citationkeypattern/CitationKeyGenerator.java
Show resolved
Hide resolved
src/main/java/org/jabref/logic/linkedfile/AbstractLinkedFileNamePatterns.java
Show resolved
Hide resolved
src/main/java/org/jabref/logic/linkedfile/AbstractLinkedFileNamePatterns.java
Show resolved
Hide resolved
src/main/java/org/jabref/logic/linkedfile/GlobalLinkedFileNamePatterns.java
Show resolved
Hide resolved
…emModel to PatternsItemModel
…ggestionCell to PatternsSuggestionCell
if ((initialNamePattern.getDefaultValue() == null) || initialNamePattern.getDefaultValue().equals(Pattern.NULL_PATTERN)) { | ||
defaultPattern = ""; | ||
} else { | ||
defaultPattern = initialNamePattern.getDefaultValue().stringRepresentation(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code violates the fail-fast principle by nesting logic inside else branch. Should check for valid state first and return/assign early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is OK in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment OK? or the code?
@Override | ||
public void setValues() { | ||
viewModel.setValues(); | ||
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct instantiation through Injector in method body violates separation of concerns. The dependency should be injected through constructor or setter method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Maybe you can add an argument BibEntryTypesManager
to the constructor of LinkedFilesTab
?
@@ -48,7 +48,7 @@ public static Optional<MetaDataDiff> compare(MetaData originalMetaData, MetaData | |||
return Optional.empty(); | |||
} else { | |||
MetaDataDiff diff = new MetaDataDiff(originalMetaData, newMetaData); | |||
List<Difference> differences = diff.getDifferences(new GlobalCitationKeyPatterns(CitationKeyPattern.NULL_CITATION_KEY_PATTERN)); | |||
List<Difference> differences = diff.getDifferences(new GlobalCitationKeyPatterns(Pattern.NULL_PATTERN)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same GlobalCitationKeyPatterns object is created twice in the class - in compare() and toString(). This violates DRY principle and creates redundant object allocations.
@@ -14,12 +14,12 @@ | |||
*/ | |||
public abstract class AbstractCitationKeyPatterns { | |||
|
|||
protected CitationKeyPattern defaultPattern = CitationKeyPattern.NULL_CITATION_KEY_PATTERN; | |||
protected Pattern defaultPattern = Pattern.NULL_PATTERN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public methods should not return null values. Consider using Optional instead of allowing null patterns, even for internal representation.
public static List<Pattern> getAllPatterns() { | ||
return Arrays.stream(Pattern.class.getDeclaredFields()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method lacks JavaDoc despite being a complex public method that uses reflection and handles exceptions. Documentation would help explain its purpose and behavior.
} | ||
|
||
/** | ||
* Gets an object for a desired key from this LinkedFileNamePattern or one of it's parents (in the case of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaDoc contains grammatical error ('it's' should be 'its') and references Hashtable in description while code uses HashMap, making documentation misleading.
} | ||
|
||
public static GlobalLinkedFileNamePatterns fromPattern(String pattern) { | ||
return new GlobalLinkedFileNamePatterns(new Pattern(pattern)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing validation for the pattern parameter before creating new Pattern object. Input parameters should be validated to fail fast.
if (preferenceFileNamePattern != null) { | ||
mainPrefsNode.put(JabRefCliPreferences.LINKED_FILE_NAME_PATTERNS_NODE, "[auth_year]"); | ||
if (prefs.hasKey(JabRefCliPreferences.IMPORT_FILENAMEPATTERN)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code violates the fail-fast principle by nesting logic inside conditional blocks instead of returning early. The nested if condition should be restructured.
@@ -68,6 +68,7 @@ public static void runMigrations(JabRefGuiPreferences preferences) { | |||
upgradeCleanups(preferences); | |||
moveApiKeysToKeyring(preferences); | |||
removeCommentsFromCustomEditorTabs(preferences); | |||
upgradeFileImportPatternToLinkedFileNamePattern(preferences, mainPrefsNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method lacks proper JavaDoc documentation explaining the migration process, parameters, and potential side effects, which is important for complex migration operations.
To remove code duplication , The thing I am not sure about is whether the preference migration is correct or not. |
<TextField fx:id="fileDirectoryPattern" GridPane.columnIndex="1" GridPane.rowIndex="1" | ||
prefWidth="300" minWidth="300" maxWidth="300"/> | ||
</GridPane> | ||
<Label text="%( Note: Press return to commit changes in the table! )"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to remove parenthesis (to ease translation).
And change text style to italics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To maintain a consistent UI across JabRef, I used it here. Should I change it?
new GlobalLinkedFileNamePatterns(filePreferences.fileNamePatternProperty().get().getDefaultValue()); | ||
patternListProperty.forEach(item -> { | ||
String patternString = item.getPattern(); | ||
if (!"default".equals(item.getEntryType().getName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic value?
Or IntelliJ IDEA hint to prevent operations on null values?
private final StringProperty fileDirectoryPatternProperty = new SimpleStringProperty(); | ||
private final BooleanProperty confirmLinkedFileDeleteProperty = new SimpleBooleanProperty(); | ||
private final BooleanProperty moveToTrashProperty = new SimpleBooleanProperty(); | ||
|
||
private final ListProperty<PatternsItemModel> patternListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); | ||
private final ObjectProperty<PatternsItemModel> defaultNamePatternProperty = new SimpleObjectProperty<>( | ||
new PatternsItemModel(new LinkedFileNamePatternsPanelViewModel.DefaultEntryType(), "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw you used empty strings (""
) in some places.
Does it differ somewhat from Pattern.NULL_PATTERN
?
@@ -103,8 +102,8 @@ public MetaData parse(Map<String, String> data, Character keywordSeparator) thro | |||
* @return the given metaData instance (which is modified, too) | |||
*/ | |||
public MetaData parse(MetaData metaData, Map<String, String> data, Character keywordSeparator) throws ParseException { | |||
CitationKeyPattern defaultCiteKeyPattern = CitationKeyPattern.NULL_CITATION_KEY_PATTERN; | |||
Map<EntryType, CitationKeyPattern> nonDefaultCiteKeyPatterns = new HashMap<>(); | |||
Pattern defaultCiteKeyPattern = org.jabref.logic.citationkeypattern.Pattern.NULL_PATTERN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactoring from CitationKeyPattern to Pattern should be accompanied by updated tests to ensure the new implementation behaves as expected.
JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output. You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide. |
Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of |
Closes #11368
This PR adds a tabular construct similar to "Key patterns" for "Linked files name" in the Linked files tab in preferences.
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)